package la.bbs558.entity.enums;

import la.bbs558.exception.MsgException;
import la.bbs558.util.Objs;
import lombok.Getter;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;

@Getter
public enum ServerTypeEnum implements Serializable {
    REGISTER("注册", 1, RedisKey.SIGN_UP_VERIFY_CODE),
    LOGIN("登录", 2, RedisKey.SIGN_IN_VERIFY_CODE),
    FORGET("找回密码", 3, RedisKey.FORGET_VERIFY_CODE)
    ;

    private final String desc;
    private final Integer code;
    private final RedisKey verifyType;

    private final static List<ServerTypeEnum> enums = Arrays.asList(values());

    ServerTypeEnum(String desc, Integer code, RedisKey verifyType) {
        this.desc = desc;
        this.code = code;
        this.verifyType = verifyType;
    }

    public static ServerTypeEnum getByName(String optType){
        for (ServerTypeEnum value : enums) {
            if(Objs.equal(value.name(),optType)){
                return value;
            }
        }
        throw new MsgException("不存在此枚举");
    }
}

